﻿using MeterReader.WebApi.Extensions;
using MeterReader.WebApi.Models;
using MeterReader.WebApi.Services.Repositories;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MeterReader.WebApi.Controllers
{
	[Route("[controller]")]
	[ApiController]
	public class SaveDataController : ControllerBase
	{
		private readonly IRepository _repository;

		public SaveDataController(IRepository repository)
        {
			_repository = repository;
		}

        [HttpPost]
		public async Task SaveData([FromBody]TMeter meter)
		{
			var newMeter =meter.ToNewTMeterList();
			await _repository.SaveDataAsync(newMeter);
		}
	}
}
